package com.ssyshop.info.utils;


import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import java.util.ArrayList;

/**
 * Created by xwc on 2017/9/1.
 * 通用工具
 */
public class Tools {

    private static Gson mGson = new Gson();

    /**
     * Gson 解析json数组
     * @param json
     * @param cls
     * @param <T>
     * @return
     */
    public static <T> ArrayList<T> fromJsonList(String json, Class<T> cls) {
        ArrayList<T> mList = new ArrayList<T>();
        JsonArray array = new JsonParser().parse(json).getAsJsonArray();
        for (final JsonElement elem : array) {
            mList.add(mGson.fromJson(elem, cls));
        }
        return mList;
    }



}
